package com.yuju.controller.pub;

import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.alibaba.fastjson.JSONObject;
import com.yuju.common.Result;
import com.yuju.controller.base.BaseController;
import com.yuju.enums.ReturnStatusEnum;
import com.yuju.rpt.enums.CheckinCustomTypeReturnCodeEnum;
import com.yuju.rpt.model.CheckinCustomTypeDetailModel;
import com.yuju.rpt.model.CheckinCustomTypeModel;
import com.yuju.rpt.service.ICheckinCustomTypeDetailService;
import com.yuju.rpt.service.ICheckinCustomTypeService;
import com.yuju.util.Utils;
import com.yuju.vo.rpt.CheckinCustomTypeVO;

/**
 * 类名：RptCheckinCustomType  <br />
 *
 * 功能：
 *
 * @author : jiaokn <br />
 * @Date : 2018年2月6日 下午2:28:45  <br />
 * @version : 1.1 <br />
 */
@Controller
@RequestMapping("rptCheckinCustomType")
public class RptCheckinCustomType extends BaseController<CheckinCustomTypeVO, CheckinCustomTypeModel> {
	
	@Autowired
	private ICheckinCustomTypeService checkinCustomTypeService;
	@Autowired
	private ICheckinCustomTypeDetailService checkinCustomTypeDetailService;
	
	/**
	 * 功能：<br/>
	 *
	 * @author jiaokn
	 * @Date 2018年2月6日 下午2:29:51 <br/>
	 */
	@RequestMapping("get")
	@ResponseBody
	public Result get(@RequestBody JSONObject obj){
		CheckinCustomTypeVO checkinCustomTypeVO = obj.toJavaObject(CheckinCustomTypeVO.class);
		Map<String, Object> map = checkinCustomTypeService.getRpt(convert(checkinCustomTypeVO));
		Result result = new Result();
		if(Utils.isNotNull(map)){
			result.setData(map.get("model"));
			result.setRows(map.get("list"));
			result.setStatus(ReturnStatusEnum.SUCCESS.getCode());
			result.setMsg(ReturnStatusEnum.SUCCESS.getDesc());
			result.setReturnCode(CheckinCustomTypeReturnCodeEnum.CHECKINCUSTOMTYPE_GET_SUCCESS.getCode());
			result.setReturnMsg(CheckinCustomTypeReturnCodeEnum.CHECKINCUSTOMTYPE_GET_SUCCESS.getDesc());
		}else{
			result.setStatus(ReturnStatusEnum.FAILURE.getCode());
			result.setMsg(ReturnStatusEnum.FAILURE.getDesc());
			result.setReturnCode(CheckinCustomTypeReturnCodeEnum.CHECKINCUSTOMTYPE_GET_FAILURE.getCode());
			result.setReturnMsg(CheckinCustomTypeReturnCodeEnum.CHECKINCUSTOMTYPE_GET_FAILURE.getDesc());
		}
		return result;
	}
	
	/**
	 * 功能：查找总计<br/>
	 *
	 * @author jiaokn
	 * @Date 2018年2月6日 下午3:20:17 <br/>
	 */
	@RequestMapping("getSum")
	@ResponseBody
	public Result getSum(@RequestBody JSONObject obj){
		CheckinCustomTypeVO checkinCustomTypeVO = obj.toJavaObject(CheckinCustomTypeVO.class);
		CheckinCustomTypeDetailModel model = checkinCustomTypeDetailService.getSum(convert(checkinCustomTypeVO));
		Result result = new Result();
		if(Utils.isNotNull(model)){
			result.setData(model);
			result.setStatus(ReturnStatusEnum.SUCCESS.getCode());
			result.setMsg(ReturnStatusEnum.SUCCESS.getDesc());
			result.setReturnCode(CheckinCustomTypeReturnCodeEnum.CHECKINCUSTOMTYPEDETAIL_SUM_SUCCESS.getCode());
			result.setReturnMsg(CheckinCustomTypeReturnCodeEnum.CHECKINCUSTOMTYPEDETAIL_SUM_SUCCESS.getDesc());
		}else{
			result.setStatus(ReturnStatusEnum.FAILURE.getCode());
			result.setMsg(ReturnStatusEnum.FAILURE.getDesc());
			result.setReturnCode(CheckinCustomTypeReturnCodeEnum.CHECKINCUSTOMTYPEDETAIL_SUM_FAILURE.getCode());
			result.setReturnMsg(CheckinCustomTypeReturnCodeEnum.CHECKINCUSTOMTYPEDETAIL_SUM_FAILURE.getDesc());
		}
		return result;
	}
	
}
